<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div id="app">
    <cpn></cpn>
    <cpn></cpn>
    <cpn ref="aaa"></cpn>
    <button @click="btnClick">按钮</button>
</div>

<template id="cpn">
    <div>我是子组件</div>
</template>
<script src="../js/vue.js"></script>
<script>
  const app = new Vue({
      el: '#app',
      data() {
          return{
              message: 'Hello Vue!'
          }
      },
      components: {
          cpn: {
              template: '#cpn',
              data() {
                  return {
                      name: '我是子组件的名字'
                  }
              },
              methods: {
                  showMessage(){
                      console.log('showMessage');
                  }
              }
          }
      },
      methods: {
          btnClick(){
              // 1. $children
              // console.log(this.$children);
              // this.$children[0].showMessage();
              // for (let c of this.$children) {
              //     console.log(c.name);
              //     c.showMessage();
              // }

              // 2. $refs =>对象类型，默认是空，需要在标签上增加属性ref="aaa"
              console.log(this.$refs.aaa.name)
          }
      }
  })
</script>

</body>
</html>
